<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  
  <link rel="stylesheet" href="plug-in/tools/css/metrole/common.css">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  
  
  <script type="text/javascript">
  	
  </script>
  <style>
    body{
    	background-color:rgb(248,249,251);    	
    }
  	.panelTitle{
  		color:#1aad19;
  		line-height: 40px;
    	height: 40px;
    	font-size: 16px;
    	text-align:center;
    	border-bottom:1px solid #e6e7ea;
    	margin-bottom:50px;
  	}
  	
  	.selectList a{
  		text-decoration: underline;
  	}
  	
  	.container{
  		background-color: white;
  		width: 80%;
    	max-width: 1280px;
    	margin: 0 auto;
    	min-height: 500px;
  	}
  	
  	.demoTable{
  		border-collapse: collapse;  		
  	}
  	
  	.demoTable td{
  		padding-bottom: 40px;
  	}
  	
  	.demoTable .tdTitle{
  		padding-right:10px;  		
  	}
  	
  	.inputxt{
  		height:30px;
  		width:80px;  		
  		text-align: right;
  	}  
  </style>
 </head>
 <body>
 <div class="container" style="padding-top:50px;">
 <!-- <div class="panelTitle">
 	请输入信息
 </div> --> 
		<table  class="demoTable">
				<tr>
					<td align="right" style="width:100px;" class="tdTitle">					
					</td>
					<td style="width:130px;text-align: right">数额</td>
					<td style="width:130px;text-align: right;">增值税</td>
					<td style="width:130px;text-align: right">数额(更正后)</td>
					<td style="width:130px;text-align: right;">增值税(更正后)</td>					
				</tr>
				<tr>
					<td align="right" style="width:100px;text-align: right" class="tdTitle">
						<label class="Validform_label">
							销售额:
						</label>
					</td>
					<td class="value" style="text-align: right">${apply.sellAmount}</td>
					<td class="value" style="text-align: right;">${apply.sellAmountTax}</td>
					<td class="value" style="text-align: right">						 	 
						<input class="inputxt" type="text" id="input1" onchange="cal()" value="${apply.sellAmount}">
					</td>
					<td class="value" style="text-align: right">						 	 
						<input style="border:none;" readonly="readonly" class="inputxt" type="text" id="input2" value="${apply.sellAmountTax}">
					</td>
					
				</tr>
				<tr>
					<td align="right" class="tdTitle">
						<label class="Validform_label">
							开支:
						</label>
					</td>
					<td class="value" style="text-align: right">${apply.spendAmount}</td>
					<td class="value" style="text-align: right;">${apply.spendAmountTax}</td>
					<td class="value" style="text-align: right">						 	 
						<input class="inputxt" type="text" id="input3" onchange="cal()" value="${apply.spendAmount}">
					</td>
					<td class="value" style="text-align: right">						 	 
						<input style="border:none;" readonly="readonly" class="inputxt" type="text" id="input4" value="${apply.spendAmountTax}">
					</td>
				</tr>
				<tr>
					<td align="right" class="tdTitle">
						<label class="Validform_label">
							利润:
						</label>
					</td>
					<td class="value" style="text-align: right">${apply.balance}</td>
					<td class="value" id="balanceTax" style="text-align:right;">						
					</td>
					<td class="value" style="text-align: right" id="balanceAmount">${apply.balance}</td>
					<td class="value" style="text-align: right" id="balanceTaxAfter"></td>
				</tr>
				<tr>
					<td colspan="5" style="text-align: center;padding-top:10px;">
						<button class="btn btn_primary btn_input" onclick="send()">保存修改</button>
						<button class="btn btn_primary btn_input" onclick="redirectPass()">直接通过</button>
					</td>
				</tr>
 			</table> 				
	</div>
 </body>
 <script type="text/javascript">
 	$(document).ready(function(){
 		moneyValidate("input1");
 		moneyValidate("input2");
 		moneyValidate("input3");
 		moneyValidate("input4");
 		
 		//计算balance的增值税
 		var balance = ${apply.balance};
 		var balanceTax = (balance/(1.0*11)).toFixed(2);
 		$("#balanceTax").text(balanceTax);
 		$('#balanceTaxAfter').text(balanceTax);
 	});
 	
 	 function cal(){
 		 var input1 = $('#input1').val();
 		 var input2 = $('#input2').val();
 		 var input3 = $('#input3').val();
 		 var input4 = $('#input4').val();
 		 
 		 input1 = parseFloat(input1);
 		 input2 = parseFloat(input2);
 		 input3 = parseFloat(input3);
		 input4 = parseFloat(input4);
 		 
 		 var balance = input1-input3;
 		 if(!isNaN(balance)){
 			$("#balanceAmount").text(balance.toFixed(2));	 
 		 }else{
 			$("#balanceAmount").text(' ');
 		 }
 		 
 		 //重新计算利润的增值税
 		 var balanceTaxAfter = (balance/(1.0*11)).toFixed(2);
  		 $('#balanceTaxAfter').text(balanceTaxAfter);
  		 
  		 $('#input2').val((input1/(1.0*11)).toFixed(2));
  		 $('#input4').val((input3/(1.0*11)).toFixed(2));

 	 }
 	
 	 function moneyValidate(id){
 		 $("#"+id).keyup(function () {
 	         var reg = $(this).val().match(/^-?\d*\.?\d{0,2}/);
 	         var txt = '';
 	         if (reg != null) {
 	             txt = reg[0];
 	         }
 	         $(this).val(txt);
 	         
 	          
 	     }).change(function () {
 	         $(this).keypress();
 	         var v = $(this).val();
 	         if (/\.$/.test(v))
 	         {
 	             $(this).val(v.substr(0, v.length - 1));
 	         }
 	         
 	         cal();
 	     }); 
 	 }
 	 
 	 function send(){
 		$.ajax({
 			url:"selectService.do?saveApplyChange",
 			type:"post",
 			data:{
 				id:"${apply.id}",
 				sellAmount:$('#input1').val(),
 				sellAmountTax:$('#input2').val(),
 				spendAmount:$('#input3').val(),
 				spendAmountTax:$('#input4').val(), 				
 				balance:$('#balance').text()
 			},
 			success:function(d){
 				 console.log(d)
  		 		 var msg = "已发送至邮箱 endure75@gmail.com";
 		 		 alert(msg);
 		 		 window.location.href="selectService.do?goAuditList"
 			}
 		});
 	 }
 		
	function redirectPass(){
		$.ajax({
 			url:"selectService.do?redirectPass",
 			type:"post",
 			data:{
 				id:"${apply.id}"
 			},
 			success:function(d){
 				 d = $.parseJSON(d);
 				 if(!d.success){
 					 alert(d.msg);
 				 }else{
 					alert(d.msg);
 					window.location.href="selectService.do?goPage6&id=${apply.id}"	 
 				 }
 			}
 		});
	}
 	
 </script>
